package cn.iocoder.yudao.module.crossborder.order.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.order.api.dto.OrderDTO;
import cn.iocoder.yudao.module.crossborder.order.api.dto.OrderCreateReqDTO;
import cn.iocoder.yudao.module.crossborder.order.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 订单管理 API 接口
 *
 * @author LHL
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 订单管理")
public interface OrderApi {

    String PREFIX = ApiConstants.PREFIX + "/order";

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "获得订单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<OrderDTO> getOrder(@RequestParam("id") @NotNull Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "获得订单列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    CommonResult<List<OrderDTO>> getOrderList(@RequestParam("ids") @NotNull List<Long> ids);

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建订单")
    CommonResult<Long> createOrder(@RequestBody @Valid OrderCreateReqDTO createReq);

    @PostMapping(PREFIX + "/cancel")
    @Operation(summary = "取消订单")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    @Parameter(name = "reason", description = "取消原因", required = true, example = "用户主动取消")
    CommonResult<Boolean> cancelOrder(@RequestParam("orderId") @NotNull Long orderId,
                                     @RequestParam("reason") @NotNull String reason);

    @PostMapping(PREFIX + "/confirm")
    @Operation(summary = "确认订单")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    CommonResult<Boolean> confirmOrder(@RequestParam("orderId") @NotNull Long orderId);

    @PostMapping(PREFIX + "/pay")
    @Operation(summary = "支付订单")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    @Parameter(name = "paymentMethod", description = "支付方式", required = true, example = "1")
    CommonResult<Boolean> payOrder(@RequestParam("orderId") @NotNull Long orderId,
                                  @RequestParam("paymentMethod") @NotNull Integer paymentMethod);

    @PostMapping(PREFIX + "/fulfill")
    @Operation(summary = "履约订单")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    CommonResult<Boolean> fulfillOrder(@RequestParam("orderId") @NotNull Long orderId);

    @PostMapping(PREFIX + "/complete")
    @Operation(summary = "完成订单")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    CommonResult<Boolean> completeOrder(@RequestParam("orderId") @NotNull Long orderId);

}
